package com.bdqn.t350.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * 数据库链接 本地1.0
   远程修改了代码1.0
   本地修改了代码2.0
   本地修改了代码3.0
   本地1.11
 */
public class BaseDao {

    Connection conn;

    /**
     * 建立连接
     *
     * @return
     */
    public Connection getConnection() {
        try {
            //加载驱动
            Class.forName("com.mysql.cj.jdbc.Driver");
            //建立数据库链接
            //conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bdqn?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai", "root", "root");
            conn = DriverManager.getConnection("jdbc:mysql://www.yuanxiaoxiang.com:3306/bdqn?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai", "root", "BDQN&123kt!@#");
            System.out.println("success");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return conn;
    }

    /**
     * 关闭连接
     *
     * @param conn
     * @param pstmt
     * @param rs
     */
    public void closeAll(Connection conn, PreparedStatement pstmt, ResultSet rs) {
        try {
            if (rs != null) {
                rs.close();
            }
            if (pstmt != null) {
                pstmt.close();
            }
            if (conn != null) {
                conn.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
       BaseDao baseDao = new BaseDao();
       baseDao.getConnection();
    }
}
